The RLastfm package: Analysis of Music Listening Habits in R

David Kang, Esha Wang

2019-03-17

Last.fm is a very basic website that is purely designed to keep track of a user’s listening habits (at least in the basic version). It links the user’s Spotify or Youtube accounts, and Last.fm simply stores the data over time. By taking advantage of Last.fm’s API, this package attempts to create useful and insightful ways to organize and display the data for a user’s music taste.

Installing RLastfm

On Windows or OS-X, the package can be installed via the following command.

install.packages("RLastfm")

Prior to running any commands for this package, run the following command in R to register the provided Google API key.

library(ggmap)
#> Loading required package: ggplot2
#> Google's Terms of Service: https://cloud.google.com/maps-platform/terms/.
#> Please cite ggmap if you use it! See citation("ggmap") for details.
ggmap::register_google("AIzaSyCGxsjtv0uCPlVnTW4-YFVqiU2APy95-gM")

Toy Data

To access full functionality of this package, internet connection (via API requests) is required. However, toy data has been provided to demonstrate the package’s basic functionality. To access the toy data, simply use toy_data.

Functions

get_listening_history

Arguments

api_key: The api key from Lastfm.

user: The username of the Lastfm account.

from: The starting timestamp in UNIX format. Default is time of the first scrobble recorded.

to: The ending timestamp in UNIX format. Default is time of the last scrobble recorded.

show_prog: If TRUE, prints which page the function is currently fetching out of total number of pages.

Return Value

Returns a dataframe that summarizes a user’s listening history.

Description

The function get_listening_history produces a dataframe that summarizes a user’s listening history, also known as “scrobbles”. Each row corresponds to a track that the user has listened to, in addition to attributes such as artist, album, time listened, etc. This function requires internet access, since the data can only be aquired through the Lastfm API.

Example

library(magrittr)
#> 
#> Attaching package: 'magrittr'
#> The following object is masked from 'package:ggmap':
#> 
#>     inset
source("../R/get_label.R")
source("../R/get_listening_history.R")
api_key = "9754b89d94c697376775c0a6896c979a"
user = "stat290_test"
get_listening_history(api_key, user) %>% head(10) %>% knitr::kable()
track artist album time_listened track_mbid artist_mbid album_mbid unix lastfm_url album_art_url
Bite The Hand Julien Baker boygenius 1552817820 NA 1552792662 https://www.last.fm/music/Julien+Baker/_/Bite+The+Hand c(“https://lastfm-img2.akamaized.net/i/u/34s/aeac79fdba138b4a59555e8164f81206.jpg”, “https://lastfm-img2.akamaized.net/i/u/64s/aeac79fdba138b4a59555e8164f81206.jpg”, “https://lastfm-img2.akamaized.net/i/u/174s/aeac79fdba138b4a59555e8164f81206.jpg”, “https://lastfm-img2.akamaized.net/i/u/300x300/aeac79fdba138b4a59555e8164f81206.jpg”)
Past Life Maggie Rogers Heard It In A Past Life 1552802400 24d0ee27-fa70-4cf6-9e7a-49287a0fa25c dde26295-8cd4-474c-8740-3edb801b2776 5b341e77-65a1-460f-b25c-1e29e97cc051 1552777243 https://www.last.fm/music/Maggie+Rogers/_/Past+Life c(“https://lastfm-img2.akamaized.net/i/u/34s/5cd218ed72b381a255794be47d4a8dac.jpg”, “https://lastfm-img2.akamaized.net/i/u/64s/5cd218ed72b381a255794be47d4a8dac.jpg”, “https://lastfm-img2.akamaized.net/i/u/174s/5cd218ed72b381a255794be47d4a8dac.jpg”, “https://lastfm-img2.akamaized.net/i/u/300x300/5cd218ed72b381a255794be47d4a8dac.jpg”)
Light On Maggie Rogers Heard It In A Past Life 1552802160 17d34a7b-2021-4dca-beb4-c945e2da1466 dde26295-8cd4-474c-8740-3edb801b2776 5b341e77-65a1-460f-b25c-1e29e97cc051 1552776981 https://www.last.fm/music/Maggie+Rogers/_/Light+On c(“https://lastfm-img2.akamaized.net/i/u/34s/5cd218ed72b381a255794be47d4a8dac.jpg”, “https://lastfm-img2.akamaized.net/i/u/64s/5cd218ed72b381a255794be47d4a8dac.jpg”, “https://lastfm-img2.akamaized.net/i/u/174s/5cd218ed72b381a255794be47d4a8dac.jpg”, “https://lastfm-img2.akamaized.net/i/u/300x300/5cd218ed72b381a255794be47d4a8dac.jpg”)
Alaska Maggie Rogers Heard It In A Past Life 1552801980 12143c25-17ee-4f11-ba7f-ba82504808a6 dde26295-8cd4-474c-8740-3edb801b2776 5b341e77-65a1-460f-b25c-1e29e97cc051 1552776792 https://www.last.fm/music/Maggie+Rogers/_/Alaska c(“https://lastfm-img2.akamaized.net/i/u/34s/5cd218ed72b381a255794be47d4a8dac.jpg”, “https://lastfm-img2.akamaized.net/i/u/64s/5cd218ed72b381a255794be47d4a8dac.jpg”, “https://lastfm-img2.akamaized.net/i/u/174s/5cd218ed72b381a255794be47d4a8dac.jpg”, “https://lastfm-img2.akamaized.net/i/u/300x300/5cd218ed72b381a255794be47d4a8dac.jpg”)
The Knife Maggie Rogers Heard It In A Past Life 1552801680 082583f9-0cda-4e43-b33d-39e6cc4c3c53 dde26295-8cd4-474c-8740-3edb801b2776 5b341e77-65a1-460f-b25c-1e29e97cc051 1552776512 https://www.last.fm/music/Maggie+Rogers/_/The+Knife c(“https://lastfm-img2.akamaized.net/i/u/34s/5cd218ed72b381a255794be47d4a8dac.jpg”, “https://lastfm-img2.akamaized.net/i/u/64s/5cd218ed72b381a255794be47d4a8dac.jpg”, “https://lastfm-img2.akamaized.net/i/u/174s/5cd218ed72b381a255794be47d4a8dac.jpg”, “https://lastfm-img2.akamaized.net/i/u/300x300/5cd218ed72b381a255794be47d4a8dac.jpg”)
Overnight Maggie Rogers Heard It In A Past Life 1552801500 3aa5deef-dee0-4046-b17a-2d20f7a88608 dde26295-8cd4-474c-8740-3edb801b2776 5b341e77-65a1-460f-b25c-1e29e97cc051 1552776312 https://www.last.fm/music/Maggie+Rogers/_/Overnight c(“https://lastfm-img2.akamaized.net/i/u/34s/5cd218ed72b381a255794be47d4a8dac.jpg”, “https://lastfm-img2.akamaized.net/i/u/64s/5cd218ed72b381a255794be47d4a8dac.jpg”, “https://lastfm-img2.akamaized.net/i/u/174s/5cd218ed72b381a255794be47d4a8dac.jpg”, “https://lastfm-img2.akamaized.net/i/u/300x300/5cd218ed72b381a255794be47d4a8dac.jpg”)
Give A Little Maggie Rogers Heard It In A Past Life 1552801260 0a84e420-3ccc-40ec-8b46-3db25057c301 dde26295-8cd4-474c-8740-3edb801b2776 5b341e77-65a1-460f-b25c-1e29e97cc051 1552776086 https://www.last.fm/music/Maggie+Rogers/_/Give+A+Little c(“https://lastfm-img2.akamaized.net/i/u/34s/5cd218ed72b381a255794be47d4a8dac.jpg”, “https://lastfm-img2.akamaized.net/i/u/64s/5cd218ed72b381a255794be47d4a8dac.jpg”, “https://lastfm-img2.akamaized.net/i/u/174s/5cd218ed72b381a255794be47d4a8dac.jpg”, “https://lastfm-img2.akamaized.net/i/u/300x300/5cd218ed72b381a255794be47d4a8dac.jpg”)
i need to be alone. Girl In Red i need to be alone. 1552800000 NA 1552774828 https://www.last.fm/music/Girl+In+Red/_/i+need+to+be+alone. c(“https://lastfm-img2.akamaized.net/i/u/34s/e4132d184d2d38a93c16e4bdec262d45.jpg”, “https://lastfm-img2.akamaized.net/i/u/64s/e4132d184d2d38a93c16e4bdec262d45.jpg”, “https://lastfm-img2.akamaized.net/i/u/174s/e4132d184d2d38a93c16e4bdec262d45.jpg”, “https://lastfm-img2.akamaized.net/i/u/300x300/e4132d184d2d38a93c16e4bdec262d45.jpg”)
Truly Twin Shadow Truly 1552799640 NA 1552774449 https://www.last.fm/music/Twin+Shadow/_/Truly c(“https://lastfm-img2.akamaized.net/i/u/34s/1e405da3869b1e30d49e9ecd19ec79ef.jpg”, “https://lastfm-img2.akamaized.net/i/u/64s/1e405da3869b1e30d49e9ecd19ec79ef.jpg”, “https://lastfm-img2.akamaized.net/i/u/174s/1e405da3869b1e30d49e9ecd19ec79ef.jpg”, “https://lastfm-img2.akamaized.net/i/u/300x300/1e405da3869b1e30d49e9ecd19ec79ef.jpg”)
No Quit Michael Nau No Quit 1552799340 NA 1552774148 https://www.last.fm/music/Michael+Nau/_/No+Quit character(0)

get_artist_info

Arguments

mbid: The 36 character MBID code for the artist.

Return Value

Returns a list of a list with the name, gender, date of birth/starting activity, genre, location MBID, city, country.

Description

The function get_artist_info produces a list of lists that summarizes an artist’s basic information, such as name, gender, date of birth/starting activity, genre, location MBID, city of birth, and country of birth. This function requires internet access, since the data can only be aquired through the MusicBrainz API. No API key is required.

Example

source("../R/get_artist_info.R")
mbid = "f4ccf6c5-ad41-4f8f-bb9e-6e2c6ad23302"
get_artist_info(mbid)
#> $mbid
#> [1] "f4ccf6c5-ad41-4f8f-bb9e-6e2c6ad23302"
#> 
#> $name
#> [1] "Deafheaven"
#> 
#> $gender
#> character(0)
#> 
#> $dob
#> [1] "2010"
#> 
#> $genres
#> [1] "blackgaze" "hipster"  
#> 
#> $location_mbid
#> [1] "83f22bb6-4631-443c-bace-9fae8540362a"
#> 
#> $city
#> [1] "San Francisco"
#> 
#> $country
#> [1] "United States"

get_album_info

Arguments

mbid: The 36 character mbid code for the album.

Return Value

Returns a list of a list with the title, artist, release_date, language, label mbid, label name, genre tags, and track list of the album.

Description

The function get_album_info produces a list of lists that summarizes an album’s basic information, such as title, artist, release_date, language, label mbid, label name, genre tags, and track list. This function requires internet access, since the data can only be aquired through the MusicBrainz API. No API key is required.

Example

source("../R/get_album_info.R")
mbid = "5b341e77-65a1-460f-b25c-1e29e97cc051"
get_album_info(mbid)
#> $mbid
#> [1] "5b341e77-65a1-460f-b25c-1e29e97cc051"
#> 
#> $title
#> [1] "Heard It in a Past Life"
#> 
#> $artist
#> [1] "Maggie Rogers"
#> 
#> $release_date
#> [1] "2019-01-18"
#> 
#> $language
#> [1] "eng"
#> 
#> $label_id
#> [1] "abea2d3e-eabf-4480-ab24-9382dd642c73"
#> 
#> $label_name
#> [1] "Capitol Records"
#> 
#> $genres
#> [1] "alternative rock" "american"         "américain"       
#> [4] "art rock"         "dance-punk"       "electronic"      
#> [7] "indie rock"       "pop"              "usa"             
#> 
#> $track_list
#>  [1] "Give a Little"   "Overnight"       "The Knife"      
#>  [4] "Alaska"          "Light On"        "Past Life"      
#>  [7] "Say It"          "On + Off"        "Fallingwater"   
#> [10] "Retrograde"      "Burning"         "Back in My Body"

get_track_info

Arguments

mbid: The 36 character mbid code for the track.

Return Value

Returns a list of a list with the track name, artist name, album, and length of the track.

Description

The function get_track_info produces a list of lists that summarizes a track’s basic information, such as track name, artist name, album, and length of the track. This function requires internet access, since the data can only be aquired through the MusicBrainz API. No API key is required.

Example

source("../R/get_track_info.R")
mbid = "082583f9-0cda-4e43-b33d-39e6cc4c3c53"
get_track_info(mbid)
#> $mbid
#> [1] "082583f9-0cda-4e43-b33d-39e6cc4c3c53"
#> 
#> $track
#> [1] "The Knife"
#> 
#> $artist
#> [1] "Maggie Rogers"
#> 
#> $album
#> [1] "Heard It in a Past Life"
#> 
#> $length
#> [1] 239

get_data

Arguments

api_key: The api key from Lastfm.

user: The user you want to search their song history for.

from: The timestamp you want to start searching song history from in UNIX format. Default is the first scrobble.

to: the timestamp upto which you want to search song history to. In UNIX format. Default is the latest scrobble.

show_prog: If TRUE, prints which page the function is currently fetching out of total number of pages.

Return Value

Comprehensive data grab of a user’s listening history with expanded information.

Description

The get_data function calls the get_listening_history, get_artist_info, get_album_info, and get_track_info functions to create a aggregate dataframe of all relevant information.

Example

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(ggmap)
source("../R/get_label.R")
source("../R/get_artist_info.R")
source("../R/get_album_info.R")
source("../R/get_track_info.R")
source("../R/get_data.R")
source("../R/get_listening_history.R")
api_key = "9754b89d94c697376775c0a6896c979a"
user = "stat290_test"
df <- get_data(api_key, user) 
#> Source : https://maps.googleapis.com/maps/api/geocode/json?address=Cincinnati&key=xxx-YFVqiU2APy95-gM
#> Source : https://maps.googleapis.com/maps/api/geocode/json?address=Stockton&key=xxx-YFVqiU2APy95-gM
#> Source : https://maps.googleapis.com/maps/api/geocode/json?address=Golden&key=xxx-YFVqiU2APy95-gM
#> Source : https://maps.googleapis.com/maps/api/geocode/json?address=Japan&key=xxx-YFVqiU2APy95-gM
#> Source : https://maps.googleapis.com/maps/api/geocode/json?address=Easton&key=xxx-YFVqiU2APy95-gM
#> Source : https://maps.googleapis.com/maps/api/geocode/json?address=London&key=xxx-YFVqiU2APy95-gM
#> Source : https://maps.googleapis.com/maps/api/geocode/json?address=United+Kingdom&key=xxx-YFVqiU2APy95-gM
df %>% head(10) %>% knitr::kable()
artist_city artist_country track_mbid album_mbid artist_mbid track artist album time_listened unix lastfm_url album_art_url artist_gender artist_dob artist_genres artist_location_mbid album_release_date album_language album_label_id album_label_name album_genres album_track_list track_length lon lat
Cincinnati United States 4c4387ce-5984-4a37-bfa0-c947f8cf1fad 5a007af7-97a1-4d8d-bf4b-fc70843557c9 88afd639-e4bd-4abd-b396-2c2d18e3157e Los Lunas Over the Rhine Love & Revelation 1552793040 1552767886 https://www.last.fm/music/Over+the+Rhine/_/Los+Lunas c(“https://lastfm-img2.akamaized.net/i/u/34s/9fdee7e2e55575bf53f22ca1618c34ff.jpg”, “https://lastfm-img2.akamaized.net/i/u/64s/9fdee7e2e55575bf53f22ca1618c34ff.jpg”, “https://lastfm-img2.akamaized.net/i/u/174s/9fdee7e2e55575bf53f22ca1618c34ff.jpg”, “https://lastfm-img2.akamaized.net/i/u/300x300/9fdee7e2e55575bf53f22ca1618c34ff.jpg”) NA 1989 folk b2cf490f-a8a7-4875-a1b7-addede3b327f 2019-03-15 eng 1ccb6c8f-edad-4933-a388-3c88b14077b3 Great Speckled Dog folk c(“Los Lunas”, “Given Road”, “Let You Down”, “Broken Angels”, “Love & Revelation”, “Making Pictures”, “Betting on the Muse”, “Leavin’ Days”, “Rocking Chair”, “May God Love You (Like You’ve Never Been Loved)”, “An American in Belfast”) 252 -84.51202 39.10312
Cincinnati United States b3273669-41ac-43fa-af48-f15fe1d952ff 5a007af7-97a1-4d8d-bf4b-fc70843557c9 88afd639-e4bd-4abd-b396-2c2d18e3157e Love & Revelation Over the Rhine Love & Revelation 1552794180 1552769026 https://www.last.fm/music/Over+the+Rhine/_/Love+&+Revelation c(“https://lastfm-img2.akamaized.net/i/u/34s/9fdee7e2e55575bf53f22ca1618c34ff.jpg”, “https://lastfm-img2.akamaized.net/i/u/64s/9fdee7e2e55575bf53f22ca1618c34ff.jpg”, “https://lastfm-img2.akamaized.net/i/u/174s/9fdee7e2e55575bf53f22ca1618c34ff.jpg”, “https://lastfm-img2.akamaized.net/i/u/300x300/9fdee7e2e55575bf53f22ca1618c34ff.jpg”) NA 1989 folk b2cf490f-a8a7-4875-a1b7-addede3b327f 2019-03-15 eng 1ccb6c8f-edad-4933-a388-3c88b14077b3 Great Speckled Dog folk c(“Los Lunas”, “Given Road”, “Let You Down”, “Broken Angels”, “Love & Revelation”, “Making Pictures”, “Betting on the Muse”, “Leavin’ Days”, “Rocking Chair”, “May God Love You (Like You’ve Never Been Loved)”, “An American in Belfast”) 156.04 -84.51202 39.10312
Cincinnati United States 0526bc06-8289-4a2a-bf49-e8d915da51e5 17554640-256e-4111-8cc5-bd65c8b76cdf 88afd639-e4bd-4abd-b396-2c2d18e3157e Let It Fall Over the Rhine Blood Oranges In The Snow 1552797060 1552771890 https://www.last.fm/music/Over+the+Rhine/_/Let+It+Fall c(“https://lastfm-img2.akamaized.net/i/u/34s/65c8fb44bb764755c7907308c7e95da8.jpg”, “https://lastfm-img2.akamaized.net/i/u/64s/65c8fb44bb764755c7907308c7e95da8.jpg”, “https://lastfm-img2.akamaized.net/i/u/174s/65c8fb44bb764755c7907308c7e95da8.jpg”, “https://lastfm-img2.akamaized.net/i/u/300x300/65c8fb44bb764755c7907308c7e95da8.jpg”) NA 1989 folk b2cf490f-a8a7-4875-a1b7-addede3b327f 2014-11-04 eng 1ccb6c8f-edad-4933-a388-3c88b14077b3 Great Speckled Dog folk c(“Blood Oranges in the Snow”, “Another Christmas”, “My Father’s Body”, “If We Make It Through December”, “Let It Fall”, “Snow Birds”, “Bethlehem”, “First Snowfall”, “New Year’s Song”) 264.536 -84.51202 39.10312
Cincinnati United States 0539a2d6-20fe-445a-8e59-4dd45060681d 17554640-256e-4111-8cc5-bd65c8b76cdf 88afd639-e4bd-4abd-b396-2c2d18e3157e Snow Birds Over the Rhine Blood Oranges In The Snow 1552797360 1552772168 https://www.last.fm/music/Over+the+Rhine/_/Snow+Birds c(“https://lastfm-img2.akamaized.net/i/u/34s/65c8fb44bb764755c7907308c7e95da8.jpg”, “https://lastfm-img2.akamaized.net/i/u/64s/65c8fb44bb764755c7907308c7e95da8.jpg”, “https://lastfm-img2.akamaized.net/i/u/174s/65c8fb44bb764755c7907308c7e95da8.jpg”, “https://lastfm-img2.akamaized.net/i/u/300x300/65c8fb44bb764755c7907308c7e95da8.jpg”) NA 1989 folk b2cf490f-a8a7-4875-a1b7-addede3b327f 2014-11-04 eng 1ccb6c8f-edad-4933-a388-3c88b14077b3 Great Speckled Dog folk c(“Blood Oranges in the Snow”, “Another Christmas”, “My Father’s Body”, “If We Make It Through December”, “Let It Fall”, “Snow Birds”, “Bethlehem”, “First Snowfall”, “New Year’s Song”) 217.621 -84.51202 39.10312
Cincinnati United States 2bfa8d2d-68be-4d71-9260-db1ed74f32be 17554640-256e-4111-8cc5-bd65c8b76cdf 88afd639-e4bd-4abd-b396-2c2d18e3157e My Father’s Body Over the Rhine Blood Oranges In The Snow 1552796340 1552771168 https://www.last.fm/music/Over+the+Rhine/_/My+Father%27s+Body c(“https://lastfm-img2.akamaized.net/i/u/34s/65c8fb44bb764755c7907308c7e95da8.jpg”, “https://lastfm-img2.akamaized.net/i/u/64s/65c8fb44bb764755c7907308c7e95da8.jpg”, “https://lastfm-img2.akamaized.net/i/u/174s/65c8fb44bb764755c7907308c7e95da8.jpg”, “https://lastfm-img2.akamaized.net/i/u/300x300/65c8fb44bb764755c7907308c7e95da8.jpg”) NA 1989 folk b2cf490f-a8a7-4875-a1b7-addede3b327f 2014-11-04 eng 1ccb6c8f-edad-4933-a388-3c88b14077b3 Great Speckled Dog folk c(“Blood Oranges in the Snow”, “Another Christmas”, “My Father’s Body”, “If We Make It Through December”, “Let It Fall”, “Snow Birds”, “Bethlehem”, “First Snowfall”, “New Year’s Song”) 218.736 -84.51202 39.10312
Cincinnati United States 1c986460-937c-4269-9779-b91a57c2514b 5a007af7-97a1-4d8d-bf4b-fc70843557c9 88afd639-e4bd-4abd-b396-2c2d18e3157e Broken Angels Over the Rhine Love & Revelation 1552793880 1552768716 https://www.last.fm/music/Over+the+Rhine/_/Broken+Angels c(“https://lastfm-img2.akamaized.net/i/u/34s/9fdee7e2e55575bf53f22ca1618c34ff.jpg”, “https://lastfm-img2.akamaized.net/i/u/64s/9fdee7e2e55575bf53f22ca1618c34ff.jpg”, “https://lastfm-img2.akamaized.net/i/u/174s/9fdee7e2e55575bf53f22ca1618c34ff.jpg”, “https://lastfm-img2.akamaized.net/i/u/300x300/9fdee7e2e55575bf53f22ca1618c34ff.jpg”) NA 1989 folk b2cf490f-a8a7-4875-a1b7-addede3b327f 2019-03-15 eng 1ccb6c8f-edad-4933-a388-3c88b14077b3 Great Speckled Dog folk c(“Los Lunas”, “Given Road”, “Let You Down”, “Broken Angels”, “Love & Revelation”, “Making Pictures”, “Betting on the Muse”, “Leavin’ Days”, “Rocking Chair”, “May God Love You (Like You’ve Never Been Loved)”, “An American in Belfast”) 296 -84.51202 39.10312
Cincinnati United States 745a5d44-b30e-4e60-b9eb-b6dc07fcd7b4 5a007af7-97a1-4d8d-bf4b-fc70843557c9 88afd639-e4bd-4abd-b396-2c2d18e3157e Let You Down Over the Rhine Love & Revelation 1552793580 1552768437 https://www.last.fm/music/Over+the+Rhine/_/Let+You+Down c(“https://lastfm-img2.akamaized.net/i/u/34s/9fdee7e2e55575bf53f22ca1618c34ff.jpg”, “https://lastfm-img2.akamaized.net/i/u/64s/9fdee7e2e55575bf53f22ca1618c34ff.jpg”, “https://lastfm-img2.akamaized.net/i/u/174s/9fdee7e2e55575bf53f22ca1618c34ff.jpg”, “https://lastfm-img2.akamaized.net/i/u/300x300/9fdee7e2e55575bf53f22ca1618c34ff.jpg”) NA 1989 folk b2cf490f-a8a7-4875-a1b7-addede3b327f 2019-03-15 eng 1ccb6c8f-edad-4933-a388-3c88b14077b3 Great Speckled Dog folk c(“Los Lunas”, “Given Road”, “Let You Down”, “Broken Angels”, “Love & Revelation”, “Making Pictures”, “Betting on the Muse”, “Leavin’ Days”, “Rocking Chair”, “May God Love You (Like You’ve Never Been Loved)”, “An American in Belfast”) 279 -84.51202 39.10312
Cincinnati United States 0ac4608a-f1c1-4f0e-b4f2-4ccd01c5d9f8 17554640-256e-4111-8cc5-bd65c8b76cdf 88afd639-e4bd-4abd-b396-2c2d18e3157e Blood Oranges In The Snow Over the Rhine Blood Oranges In The Snow 1552795800 1552770620 https://www.last.fm/music/Over+the+Rhine/_/Blood+Oranges+In+The+Snow c(“https://lastfm-img2.akamaized.net/i/u/34s/65c8fb44bb764755c7907308c7e95da8.jpg”, “https://lastfm-img2.akamaized.net/i/u/64s/65c8fb44bb764755c7907308c7e95da8.jpg”, “https://lastfm-img2.akamaized.net/i/u/174s/65c8fb44bb764755c7907308c7e95da8.jpg”, “https://lastfm-img2.akamaized.net/i/u/300x300/65c8fb44bb764755c7907308c7e95da8.jpg”) NA 1989 folk b2cf490f-a8a7-4875-a1b7-addede3b327f 2014-11-04 eng 1ccb6c8f-edad-4933-a388-3c88b14077b3 Great Speckled Dog folk c(“Blood Oranges in the Snow”, “Another Christmas”, “My Father’s Body”, “If We Make It Through December”, “Let It Fall”, “Snow Birds”, “Bethlehem”, “First Snowfall”, “New Year’s Song”) 312.034 -84.51202 39.10312
Cincinnati United States 7ac6996a-ac18-48f7-8a6b-a8e83c8b4ef5 5a007af7-97a1-4d8d-bf4b-fc70843557c9 88afd639-e4bd-4abd-b396-2c2d18e3157e May God Love You (Like You’ve Never Been Loved) Over the Rhine Love & Revelation 1552795440 1552770258 https://www.last.fm/music/Over+the+Rhine/_/May+God+Love+You+(Like+You%27ve+Never+Been+Loved) c(“https://lastfm-img2.akamaized.net/i/u/34s/9fdee7e2e55575bf53f22ca1618c34ff.jpg”, “https://lastfm-img2.akamaized.net/i/u/64s/9fdee7e2e55575bf53f22ca1618c34ff.jpg”, “https://lastfm-img2.akamaized.net/i/u/174s/9fdee7e2e55575bf53f22ca1618c34ff.jpg”, “https://lastfm-img2.akamaized.net/i/u/300x300/9fdee7e2e55575bf53f22ca1618c34ff.jpg”) NA 1989 folk b2cf490f-a8a7-4875-a1b7-addede3b327f 2019-03-15 eng 1ccb6c8f-edad-4933-a388-3c88b14077b3 Great Speckled Dog folk c(“Los Lunas”, “Given Road”, “Let You Down”, “Broken Angels”, “Love & Revelation”, “Making Pictures”, “Betting on the Muse”, “Leavin’ Days”, “Rocking Chair”, “May God Love You (Like You’ve Never Been Loved)”, “An American in Belfast”) 235.12 -84.51202 39.10312
Cincinnati United States cea68be9-8fe9-4c9d-8523-9f4af769eca3 5a007af7-97a1-4d8d-bf4b-fc70843557c9 88afd639-e4bd-4abd-b396-2c2d18e3157e Rocking Chair Over the Rhine Love & Revelation 1552795080 1552769895 https://www.last.fm/music/Over+the+Rhine/_/Rocking+Chair c(“https://lastfm-img2.akamaized.net/i/u/34s/9fdee7e2e55575bf53f22ca1618c34ff.jpg”, “https://lastfm-img2.akamaized.net/i/u/64s/9fdee7e2e55575bf53f22ca1618c34ff.jpg”, “https://lastfm-img2.akamaized.net/i/u/174s/9fdee7e2e55575bf53f22ca1618c34ff.jpg”, “https://lastfm-img2.akamaized.net/i/u/300x300/9fdee7e2e55575bf53f22ca1618c34ff.jpg”) NA 1989 folk b2cf490f-a8a7-4875-a1b7-addede3b327f 2019-03-15 eng 1ccb6c8f-edad-4933-a388-3c88b14077b3 Great Speckled Dog folk c(“Los Lunas”, “Given Road”, “Let You Down”, “Broken Angels”, “Love & Revelation”, “Making Pictures”, “Betting on the Muse”, “Leavin’ Days”, “Rocking Chair”, “May God Love You (Like You’ve Never Been Loved)”, “An American in Belfast”) 231 -84.51202 39.10312

get_artist_map

Arguments

df: Dataframe of scrobles, tidied with artist location of birth along with longitude and lattitude.

Return Value

Returns a map image, where each point on the map indicates an artist who was born there.

Description

Generate world map of where artists were born based on a user’s listening history. This will require use of Google’s ggmap API.

Example

source("../R/artist_map.R")
get_artist_map(df)

get_wordcloud

Arguments

data: Dataframe of scrobles, tidied.

Return Value

Returns a wordcloud image, where bigger words indicated greater weight in genre.

Description

Generate WordCloud of music genres based on a user’s listening history.

Example

source("../R/wordcloud.R")
get_wordcloud(df)

get_loved_tracks

Arguments

user: The user name to fetch the loved tracks for.

api_key: A Last.fm API key.

Return Value

Returns an list of loved tracks for a given user.

Description

Creates a tibble of loved tracks that a user as bookmarked on Last.fm.

Example

source("../R/get_loved_tracks.R")
api_key = "9754b89d94c697376775c0a6896c979a"
user = "stat290_test"
get_loved_tracks(api_key, user)
#> # A tibble: 28 x 3
#>    track_mbid                        track              time               
#>    <chr>                             <chr>              <dttm>             
#>  1 61de899f-5d4e-43f3-bbf1-7e36a6d7… Say It             2019-03-17 03:23:00
#>  2 3788b91b-f00f-4485-be30-8bafc745… On + Off           2019-03-17 03:23:00
#>  3 <NA>                              Turn the Light     2019-03-17 03:23:00
#>  4 0dca44e6-d4a8-48cd-be99-af855b55… Slow Burn          2019-03-17 03:23:00
#>  5 303a7970-49e7-4c47-94e3-7563e50a… Oh, What a World   2019-03-17 03:23:00
#>  6 2e644590-e52c-4585-a4ac-62a88b71… Rainbow            2019-03-17 03:23:00
#>  7 06c07e50-f230-4f46-b325-b7012bcd… Love Is a Wild Th… 2019-03-17 03:23:00
#>  8 5b897a81-7ccd-47d6-b098-e6aa546f… Mother             2019-03-17 03:23:00
#>  9 05820d1b-0002-4360-a793-2be766f4… Happy & Sad        2019-03-17 03:23:00
#> 10 2259c689-3979-4248-b7b4-6366af1b… High Horse         2019-03-17 03:23:00
#> # … with 18 more rows

get_top_artists

Arguments

api_key: The api key from Lastfm.

user: The user you want to search their artist history for.

period: The timeframe within which you want your search to be options are “overall”, “7day”, “1month”, “3month”, “6month”, “12month.” Default is 7 days.

show_prog: If TRUE, prints which page the function is currently fetching out of total number of pages.

pages: If set to “one”, returns just the first page of the API request output.

Return Value

Returns a tibble with rank, top artists, artist play count, artist MBID code, and a url to the artist’s picture.

Description

Returns a dataframe of the user’s top artists.

Example

source("../R/get_top_artists.R")
api_key = "9754b89d94c697376775c0a6896c979a"
user = "dkang9503"
get_top_artists(api_key, user)
#> # A tibble: 91 x 5
#>     Rank Artist        `Play Count` `Artist MBID`         `Artist Picture …
#>    <dbl> <chr>                <dbl> <chr>                 <list>           
#>  1     1 Duke Ellingt…           74 3af06bc4-68ad-4cae-b… <chr [1]>        
#>  2     2 Everything B…           38 959cf5bf-ee29-4af6-a… <chr [1]>        
#>  3     3 Lucy Dacus              31 dbe7fdf7-81b2-418b-b… <chr [1]>        
#>  4     4 John Fahey              29 95bb27d2-43c7-4a92-8… <chr [1]>        
#>  5     5 Carpenters              27 4580d83b-093e-4241-9… <chr [1]>        
#>  6     6 Haley Heynde…           26 f0805df4-1541-48b1-8… <chr [1]>        
#>  7     7 Hannah Georg…           25 9074ba02-319a-4882-b… <chr [1]>        
#>  8     8 Maggie Rogers           18 dde26295-8cd4-474c-8… <chr [1]>        
#>  9     9 Over the Rhi…           18 88afd639-e4bd-4abd-b… <chr [1]>        
#> 10    10 Kacey Musgra…           16 d1393ecb-431b-4fde-a… <chr [1]>        
#> # … with 81 more rows

get_top_albums

Arguments

api_key: The api key from Last.fm.

user: The user you want to search their album history for.

period: The timeframe within which you want your search to be options are “overall”, “7day”, “1month”, “3month”, “6month”, “12month.” Default is 7 days.

show_prog: If TRUE, prints which page the function is currently fetching out of total number of pages.

pages: If “one”, returns just the first page of the API request output.

Return Value

Returns a tibble with rank, album name, play count, artist name, artist MBID, and a url to the album art.

Description

Returns a dataframe of the user’s top albums.

Example

source("../R/get_top_albums.R")
api_key = "9754b89d94c697376775c0a6896c979a"
user = "dkang9503"
get_top_albums(api_key, user)
#> # A tibble: 135 x 6
#>    Rank  Album       `Play Count` Artist   `Artist MBID`    `Album Art Url`
#>    <chr> <chr>       <chr>        <chr>    <chr>            <list>         
#>  1 1     Never No L… 74           Duke El… 3af06bc4-68ad-4… <chr [1]>      
#>  2 2     Death Chan… 22           John Fa… 95bb27d2-43c7-4… <chr [1]>      
#>  3 3     I Need to … 21           Haley H… f0805df4-1541-4… <chr [1]>      
#>  4 4     Close To Y… 19           Carpent… 4580d83b-093e-4… <chr [1]>      
#>  5 5     Amplified … 19           Everyth… 959cf5bf-ee29-4… <chr [1]>      
#>  6 6     No Burden   19           Lucy Da… dbe7fdf7-81b2-4… <chr [1]>      
#>  7 7     Heard It I… 18           Maggie … dde26295-8cd4-4… <chr [1]>      
#>  8 8     Golden Hour 16           Kacey M… d1393ecb-431b-4… <chr [1]>      
#>  9 9     When I Get… 16           Solange  410e7fd3-b865-4… <chr [1]>      
#> 10 10    This Is Ho… 13           Helado … aa0a54b3-d37e-4… <chr [1]>      
#> # … with 125 more rows

get_top_tracks

Arguments

api_key: The api key from Last.fm.

user: The user you want to search their track history for.

period: The timeframe within which you want your search to be options are “overall”, “7day”, “1month”, “3month”, “6month”, “12month.” Default is 7 days.

show_prog: If TRUE, prints which page the function is currently fetching out of total number of pages.

pages: If “one”, returns just the first page of the API request output.

Return Value

Returns a tibble with rank, top tracks, track play count, song duration, artist name, artist MBID code, and a url to the artist’s picture.

Description

Returns a dataframe of the user’s top artists.

Example

source("../R/get_top_tracks.R")
api_key = "9754b89d94c697376775c0a6896c979a"
user = "dkang9503"
get_top_tracks(api_key, user)

get_similar_tracks

Arguments

api_key: The api key from Lastfm.

artist: The artist you want to find similar artists to.

track: The corresponding track you want to find similar artists to.

num_return: The number of artists you want to be returned. Default is 10.

Return Value

Returns a vector of recommended tracks and a similarity rating for said track.

Description

Given an artist and a track name, get_similar_tracks generates num_return tracks that are most similar based on Last.fm’s similarity rating.

Example

source("../R/get_top_tracks.R")
source("../R/get_similar_tracks.R")
api_key = "9754b89d94c697376775c0a6896c979a"
artist = "Nujabes"
track = "Flowers"
get_similar_tracks(api_key, artist, track)
#> $rec_track
#>  [1] "Light on the Land" "Music Is Mine"     "battlecry"        
#>  [4] "Ole"               "Chambers"          "Just Forget"      
#>  [7] "Evening Comes"     "Luv Letter"        "Essential Violet" 
#> [10] "Natural Green"    
#> 
#> $rec_artist
#>  [1] "Nujabes"               "Nujabes"              
#>  [3] "Nujabes feat. Shing02" "Fat Jon"              
#>  [5] "Fat Jon"               "Force of Nature"      
#>  [7] "DJ Okawari"            "DJ Okawari"           
#>  [9] "Blazo"                 "Blazo"                
#> 
#> $rec_sim_rating
#>  [1] 1.000 0.973 0.234 0.228 0.216 0.200 0.122 0.107 0.096 0.087

track_recommendations

Arguments

api_key: The api key from Lastfm.

user: The user you want to search their listening history for.

period: The timeframe within which you want your search to be options are “overall”, “7day”, “1month”, “3month”, “6month”, “12month.” Default is 7 days. Longer time periods will take longer time.

test: A parameter to make the example case load faster.

Return Value

Returns a tibble with the recommended tracks and a recommendation rating based on Last.fm’s similarity score and number of listens.

Description

Gives a user recommendations of tracks to listen to based on their listening history.

Example

source("../R/track_recommendations.R")
api_key = "9754b89d94c697376775c0a6896c979a"
user = "stat290_test"
track_recommendations(api_key, user, test = TRUE)
#> # A tibble: 36 x 3
#> # Groups:   tracks [36]
#>    tracks        artists                   rec_rating
#>    <chr>         <chr>                          <dbl>
#>  1 The Knife     Maggie Rogers                  11.4 
#>  2 Overnight     Maggie Rogers                  11.4 
#>  3 Past Life     Maggie Rogers                  10.9 
#>  4 Give A Little Maggie Rogers                  10.7 
#>  5 Fallingwater  Maggie Rogers                   5.70
#>  6 On + Off      Maggie Rogers                   5.70
#>  7 Light On      Maggie Rogers                   5.41
#>  8 Adore         Amy Shark                       4.53
#>  9 Sugar         Terror Jr                       3.82
#> 10 Power Down    Benjamin Francis Leftwich       2.96
#> # … with 26 more rows

get_similar_artist

Arguments

api_key: The api key from Lastfm.

artist: The artist you want to find similar artists to.

num_return: The number of artists you want to be returned.

mbid: A boolean of whether or not the artist parameter is a unique mbid of an artist. Default is false.

Return Value

Given an artist, returns a vector of artists and a vector similarity rating for said artist.

Description

Given an artist, get_similar_tracks generates num_return artists that are most similar based on Last.fm’s similarity rating.

Example

source("../R/get_similar_artist.R")
api_key = "9754b89d94c697376775c0a6896c979a"
artist = "Prince"
get_similar_artist(api_key, artist)
#> $rec_artist
#>  [1] "Prince & The Revolution"            
#>  [2] "The Time"                           
#>  [3] "Prince and the New Power Generation"
#>  [4] "Sheila E."                          
#>  [5] "Wendy & Lisa"                       
#>  [6] "The Family"                         
#>  [7] "Madhouse"                           
#>  [8] "Vanity 6"                           
#>  [9] "Stevie Wonder"                      
#> [10] "Terence Trent D'Arby"               
#> 
#> $rec_sim_rating
#>  [1] 1.000000 0.921503 0.921494 0.588352 0.354108 0.336150 0.276339
#>  [8] 0.274795 0.237341 0.234175

artist_recommendations

Arguments

api_key: The api key from Lastfm.

user: The user you want to search their track history for.

period: The timeframe within which you want your search to be options are “overall”, “7day”, “1month”, “3month”, “6month”, “12month.” Default is 7 days. Longer time periods will take longer time.

Return Value

Returns a tibble with the recommended artists and a recommendation rating based on Last.fm’s similarity score and number of listens.

Description

Gives a user recommendations of artists to listen to based on their listening history.

Example

source("../R/artist_recommendations.R")
api_key = "9754b89d94c697376775c0a6896c979a"
user = "stat290_test"
period = "overall"
artist_recommendations(api_key, user)
#> # A tibble: 87 x 2
#>    artists            rec_rating
#>    <chr>                   <dbl>
#>  1 King Princess            5.13
#>  2 Derek Webb               4.06
#>  3 Sigrid                   4.06
#>  4 Rosie Thomas             3.93
#>  5 Maren Morris             3.25
#>  6 Xavier Omär              3.25
#>  7 The Japanese House       3.21
#>  8 Léon                     3.12
#>  9 Chelsea Jade             3.09
#> 10 Yogee New Waves          2.77
#> # … with 77 more rows

album_chart

Arguments

api_key: The api key from Lastfm.

user: The user you want to look up info for.

period: The timeframe within which you want your search to be options are “overall”, “7day”, “1month”, “3month”, “6month”, “12month.” Default is 7 days.

size: The size of the chart you want to produce. Can pick any number from 2 to 10.

display: Option of whether or not you want labels for artist, album, play count, and rank. Input as a vector of options e.g. c(‘artist’, ‘album’, ‘playcount’, ‘rank’).

Return Value

Returns an image of the chart of the top albums a user listened to in a given timeframe.

Description

Creates a chart of the top albums a user listens to in a given time period.

Example

source("../R/album_chart.R")
api_key = "9754b89d94c697376775c0a6896c979a"
user = "dkang9503"
album_chart(api_key, user, display = c('artist', 'album'))

artist_chart

Arguments

api_key: The api key from Lastfm.

user: The user you want to look up info for.

period: The timeframe within which you want your search to be options are “overall”, “7day”, “1month”, “3month”, “6month”, “12month.” Default is 7 days.

size: The size of the chart you want to produce. Can pick any number from 2 to 10.

display: Option of whether or not you want labels for artist, album, play count, and rank. Input as a vector of options e.g. c(‘artist’, ‘playcount’, ‘rank’).

Return Value

Returns an image of the chart of the top artists a user listened to in a given timeframe.

Description

Creates a chart of the top artists a user listens to in a given time period.

Example

source("../R/artist_chart.R")
api_key = "9754b89d94c697376775c0a6896c979a"
user = "dkang9503"
artist_chart(api_key, user, display = c('artist'))

mainstream_chart

Arguments

api_key: The api key from Lastfm.

user: The user you want to search their album history for.

period: The timeframe within which you want your search to be options are “overall”, “7day”, “1month”, “3month”, “6month”, “12month.” Default is 7 days.

num_artist: Number of artist you want to specify in the plots. Default is 20.

Return Value

Returns a chart outlining how mainstream a user’s top artists are.

Description

Returns a chart outlining how mainstream a user’s top 20 artists are.

Example

source("../R/mainstream_chart.R")
api_key = "9754b89d94c697376775c0a6896c979a"
user = "dkang9503"
mainstream_chart(api_key, user)

time_spent_listening

Arguments

api_key: The api key from Lastfm.

user: The user you want to search their track history for.

period: The timeframe within which you want your search to be options are “overall”, “7day”, “1month”, “3month”, “6month”, “12month.” Default is 7 days. Longer time periods will take longer time.

show_prog: If TRUE, prints which page the function is currently fetching out of total number of pages.

num_artist: Number of artists you want to retrieve listening information about.

Return Value

Returns two plots showing number of minutes spent listening to artist and the percentage of time listening to each artist.

Description

Returns two charts detailing the amount of time a user spent listening to specific artists. This is going to take a while, ignore the request fails. This function might take a while because we have to fetch missing track duration data.

Example

source("../R/time_spent_listening.R")
api_key = "9754b89d94c697376775c0a6896c979a"
user = "stat290_test"
period = "overall"
time_spent_listening(api_key, user, period)

Contributions

David

album_chart, artist_chart, mainstream_chart, artist_recommendations, time_spent_listening, get_similar_artists, get_similar_tracks, get_album_info, get_artist_info, get_listening_history, get_track_info, get_top_albums, get_top_artists, get_top_tracks, test cases

Esha

artist_map, get_loved_tracks, wordcloud, get_data, get_similar_tracks, track_recommendations, get_album_info, get_artist_info, get_listening_history, get_track_info, get_top_albums, get_top_artists, get_top_tracks, vignette